package com.itheima.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class JpaUtil {
    //定义JPA的实体管理器工厂
    private static EntityManagerFactory factory;

    //通过静态代码块给实体类管理器工厂赋值,确保只生成一个实体管理器共产对象
    static {
        factory = Persistence.createEntityManagerFactory("myJpa");
    }

    //使用管理器工厂生产一个管理器对象
    public static EntityManager createEntityManager() {
        return factory.createEntityManager();
    }
}
